package com.xbongbong.saas.util;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.sys.domain.entity.DepartmentEntity;

import java.util.Map;

/**
 *
 * 组织架构相关帮助类
 * @author kaka
 * @version v1.0
 * @date 2020/12/21 15:53
 * @since v1.0
 */
public class OrganizationUtil {

    /**
     * 部门路由拼接
     * @param dep 需要设置路由的部门
     * @param depIdPIdMap 部门id：父部门id的map
     * 创建时间 2019/1/29 1:45 PM
     * 修改时间 2019/1/29 1:45 PM
     * @author chy
     * @since v3.37
     * @version v3.37
     */
    public static void setDepIdRouter(DepartmentEntity dep, Map<Long, Long> depIdPIdMap){
        StringBuilder depIdRouter = new StringBuilder();
        depIdRouter.append(PaasConstant.ROLE_DELIMITER).append(dep.getId()).append(PaasConstant.ROLE_DELIMITER);
        Long pid = dep.getParentId();
        while (pid != null && !pid.equals(0L)) {
            depIdRouter.insert(0, pid).insert(0, PaasConstant.ROLE_DELIMITER);
            pid = depIdPIdMap.get(pid);
        }
        dep.setDepIdRouter(depIdRouter.toString());
    }

}
